<template>
  <div class="app-container">
    <div style="float: right">
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
      >
        <el-button
          type="primary"
          @click="handleAdd"
          >新增</el-button
        >
      </el-form>
    </div>

    <el-table
      v-loading="loading"
      :data="rulesList"
    >
      <el-table-column
        label="区县"
        align="center"
        prop="regionNameList[0]"
      />
      <el-table-column
        label="起步价"
        align="center"
        prop="timePeriodList[0].startingPrice"
      />
      <el-table-column
        label="信息费"
        align="center"
        prop="informationFee"
      />
      <el-table-column
        label="保险费"
        align="center"
        prop="insurancePremium"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            icon="Edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:coupon:edit']"
            >编辑</el-button
          >
          <el-button
            link
            type="primary"
            icon="Delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:coupon:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script setup name="Rules">
import { getRules } from "@/api/system/rules";
import { onMounted } from "vue";

const { proxy } = getCurrentInstance();

const rulesList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
  },
});

const { form, queryParams } = toRefs(data);

function getList() {
  getRules().then((res) => {
    rulesList.value = res.data;
    loading.value = false;
  });
}

function handleAdd() {
  proxy.$router.push({ path: "/rules-manage/rules-add" });
}

function handleUpdate(row) {
  console.log(row,'编辑运价规则传给后端的数据')
  proxy.$router.push({
    path: "/rules-manage/rules-add",
    query: {
      form: JSON.stringify(row),
    },
  });
}

function handleDelete() {}
// getList();

onMounted(() => {
  alert('ttttt')
  getList();
})
</script>
